/*
ID:luongho3
LANG:JAVA
TASK:dualpal
 */
package usaco.training.chap1.sec2;

import java.io.File;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Scanner;

public class dualpal {

	static int N, S;

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("dualpal.in"));
		PrintStream ps = new PrintStream(new File("dualpal.out"));
		System.setOut(ps);
		N = scanner.nextInt();
		S = scanner.nextInt();
		for (int i=S+1;N>0;++i) {
			int count = 0;
			String s = i + "";
			BigInteger b = new BigInteger(s);
			for (int j=2;j<=10;++j) {
				if (palin(b.toString(j))) {
					count++;
					if (count == 2) {
						break;
					}
				}
			}
			if (count >= 2) {
				N--;
				System.out.println(i);
			}
		}
	}
	
	private static boolean palin(String string) {
		int len = string.length();
		int st = 0;
		int en = len - 1;
		while (st < en) {
			if (string.charAt(st) == string.charAt(en)) {
				st++;
				en--;
				continue;
			}
			else {
				return false;
			}
		}
		return true;
	}

}
